package com.card.redis;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * ClassName: RedisConfig <br/>
 * Function: redis Config. <br/>
 * date: 2018年08月20日 下午9:35:54 <br/>
 * 
 * @author lishuai8
 * @version
 * @since JDK 1.8
 */
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {

	@Value("${spring.redis.host}")
	private String host;

	@Value("${spring.redis.port}")
	private String port;

	@Value("${spring.redis.timeout}")
	private String timeout;

	@Value("${spring.redis.pool.max-idle}")
	private String maxIdle;

	@Value("${spring.redis.pool.max-wait}")
	private String maxWaitMillis;

	@Value("${spring.redis.password}")
	private String password;

	@Bean
	public JedisPool redisPoolFactory() {
		JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
		jedisPoolConfig.setMaxIdle(Integer.valueOf(maxIdle));
		jedisPoolConfig.setMaxWaitMillis(Integer.valueOf(maxWaitMillis));
		JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, Integer.valueOf(port), Integer.valueOf(timeout),
				password);
		return jedisPool;
	}

}
